# -*- coding: utf-8 -*-
# owner: shenyi
# file: src/models/responses.py

from typing import List, Optional
from pydantic import BaseModel, Field


class DeleteResponse(BaseModel):
    status_code: int = Field(default=200, description="HTTP 状态码")
    message: str = Field(default="ok", description="响应消息")


class CreateResponse(BaseModel):
    status_code: int = Field(default=200, description="HTTP 状态码")
    message: str = Field(default="ok", description="响应消息")
    instance_ids: List[str] = Field(default_factory=list, description="创建成功的实例 ID 列表")


class InstanceType(BaseModel):
    instance_type_id: str = Field(..., description="实例规格 ID")
    cpu_core_count: int = Field(..., description="CPU 核心数")
    memory_size: int = Field(..., description="内存大小（单位：GB 或 MB，需统一）")
    cpu_architecture: Optional[str] = Field(None, description="CPU 架构，如 x86_64、arm64")


class InstanceTypeResponse(BaseModel):
    status_code: int = Field(default=200, description="HTTP 状态码")
    message: str = Field(default="success", description="响应消息")
    instance_types: List[InstanceType] = Field(default_factory=list, description="可用实例规格列表")


class AvailableZoneInstanceType(BaseModel):
    available: bool = Field(default=True, description="该规格在该可用区是否可用")
    instance_type_id: str = Field(default="", description="实例规格 ID")
    zone_id: str = Field(default="", description="可用区 ID")


class AvailableZonesInstanceTypeResponse(BaseModel):
    status_code: int = Field(default=200, description="HTTP 状态码")
    message: str = Field(default="success", description="响应消息")
    available_zones: List[AvailableZoneInstanceType] = Field(
        default_factory=list,
        description="各可用区的实例规格可用性列表"
    )
    
# =============== 实例详情模型 ===============

class Instance(BaseModel):
    instance_id: str = Field(..., description="实例唯一标识符")
    name: Optional[str] = Field(None, description="实例名称（别名）")
    instance_type_id: str = Field(..., description="实例规格 ID")
    status: str = Field(..., description="实例状态，如 running, stopped, pending 等")
    region_id: str = Field(..., description="地域 ID")
    zone_id: str = Field(..., description="可用区 ID")
    private_ip: Optional[str] = Field(None, description="内网 IP 地址")
    public_ip: Optional[str] = Field(None, description="公网 IP 地址")
    image_id: Optional[str] = Field(None, description="镜像 ID")
    vpc_id: Optional[str] = Field(None, description="VPC ID")
    subnet_id: Optional[str] = Field(None, description="子网 ID")
    created_at: Optional[str] = Field(None, description="创建时间，ISO8601 格式")
    provider: str = Field(..., description="云厂商，如 aliyun, aws, tencent 等")


class InstanceResponse(BaseModel):
    status_code: int = Field(default=200, description="HTTP 状态码")
    message: str = Field(default="success", description="响应消息")
    instance: Instance = Field(..., description="实例详情")


class InstanceListResponse(BaseModel):
    status_code: int = Field(default=200, description="HTTP 状态码")
    message: str = Field(default="success", description="响应消息")
    instances: List[Instance] = Field(default_factory=list, description="实例列表")